#delimit;
clear all;
set more off;


#delimit cr
capture progam drop get_star_coeff
program define get_star_coeff, rclass
	
	local point_est = r(estimate)
	local est_se = r(se)
	local df = r(df)
	
	local t_stat = abs(`point_est'/`est_se')
	
	local crit_val_point1 = invttail(`df',0.05)
	local crit_val_point05 = invttail(`df',0.025)
	local crit_val_point01 = invttail(`df',0.005)
	local crit_val_point001 = invttail(`df',0.0005)
	
	if `t_stat' <= `crit_val_point1' {
		local tau_dat string(round(`point_est', .001)) 
	}
	else if `t_stat' >= `crit_val_point1' & `t_stat' < `crit_val_point05' {
		local tau_dat string(round(`point_est', .001)) + "\sym{+}"
	} 
	else if `t_stat' >= `crit_val_point05' & `t_stat' < `crit_val_point01' {
		local tau_dat string(round(`point_est', .001)) + "\sym{*}"
	} 
	else if `t_stat' >= `crit_val_point01' & `t_stat' < `crit_val_point001' {
		local tau_dat string(round(`point_est', .001)) + "\sym{**}"
	} 
	else {
		local tau_dat string(round(`point_est', .001)) + "\sym{***}"
	}
	
	return local tau_dat = `tau_dat'
	 
end


#delimit;
clear;
use "voter_file_hist_all_imp.dta";





replace age = 20 if age == 220;
replace age = 20 if age == 120;
replace age = . if age <= 17;
replace age = . if age >= 105;


gen age_gr = 1 if age >= 18 & age <= 24;
replace age_gr = 2 if age >= 25 & age <= 34;
replace age_gr = 3 if age >= 35 & age <= 44;
replace age_gr = 4 if age >= 45 & age <= 54;
replace age_gr = 5 if age >= 55 & age <= 64;
replace age_gr = 6 if age >= 65 & age <= 74;
replace age_gr = 7 if age >= 75;

tab race_cat_vf, gen(race_inds);



#delimit cr
program define pe
	version 12.0
	if `"`0'"' != "" {
		display as text `"`0'"'
		`0'
		display("")
	}
end


#delimit;

*Add Valdosta and Dalton County Indicators; 
gen valdosta_msa = 0;
replace valdosta_msa = 1 if county_code == 92 | county_code == 14 | county_code == 50 | county_code == 86;

gen dalton_msa = 0;
replace dalton_msa = 1 if county_code == 105 | county_code == 155;


#delimit;
*Coding year of registration;
tostring registration_date, replace;
gen registration_year = substr(registration_date, 1, 4);
destring registration_year, replace;
*Cleaning error in one registration date;
tab registration_date if registration_year > 2020;
replace registration_year = 2010 if registration_year == 5201;
drop registration_date;

*Creating unique precinct IDs;
egen precinct_ID = group(county_precinct_id county_code);

*Generating binary turnout variables;
gen to_2021_ro  = . if registration_year > 2021;
replace to_2021_ro = 0 if y2021_004_vote == "NV" & registration_year <= 2021;
replace to_2021_ro = 1 if y2021_004_vote != "NV" & registration_year <= 2021;

gen to_2020_gen = . if registration_year > 2020;
replace to_2020_gen = 0 if y2020_003_vote == "NV" & registration_year <= 2020;
replace to_2020_gen = 1 if y2020_003_vote != "NV" & registration_year <= 2020;

gen to_2020_prim = . if registration_year > 2020;
replace to_2020_prim = 0 if y2020_001_vote == "NV" & registration_year <= 2020;
replace to_2020_prim = 1 if y2020_001_vote != "NV" & registration_year <= 2020;

gen to_2018_ro = . if registration_year > 2018;
replace to_2018_ro = 0 if y2018_004_vote  == "NV" & registration_year <= 2018;
replace to_2018_ro = 1 if y2018_004_vote  != "NV" & registration_year <= 2018;

gen to_2018_gen = . if registration_year > 2018;
replace to_2018_gen = 0 if y2018_003_vote  == "NV" & registration_year <= 2018;
replace to_2018_gen = 1 if y2018_003_vote  != "NV" & registration_year <= 2018;

gen to_2018_prim = . if registration_year > 2018;
replace to_2018_prim = 0 if y2018_001_vote  == "NV" & registration_year <= 2018;
replace to_2018_prim = 1 if y2018_001_vote  != "NV" & registration_year <= 2018;

gen to_2016_gen = . if registration_year > 2016;
replace to_2016_gen = 0 if y2016_003_vote  == "NV" & registration_year <= 2016;
replace to_2016_gen = 1 if y2016_003_vote  != "NV" & registration_year <= 2016;

gen to_2014_gen = . if registration_year > 2014;
replace to_2014_gen = 0 if y2014_003_vote  == "NV" & registration_year <= 2014;
replace to_2014_gen = 1 if y2014_003_vote  != "NV" & registration_year <= 2014;


gen rep_prim_2020 = 1 if y2020_001_party == "R ";
replace rep_prim_2020 = 0 if y2020_001_party != "R ";

gen dem_prim_2020 = 1 if y2020_001_party == "D ";
replace dem_prim_2020 = 0 if y2020_001_party != "D ";

gen in_balanced_panel = 1 if to_2014_gen != . & to_2016_gen != . & to_2018_gen != . & to_2020_gen != .;


gen only_2016g_2020g = 1 if to_2020_gen == 1 & to_2016_gen == 1 & to_2020_prim == 0 & to_2018_ro == 0 & to_2018_gen == 0 & to_2014_gen == 0;
#delimit;

gen nd_pres_app_bin_ga_rv_extend = pres_app_bin_ga_rv_extend;
replace nd_pres_app_bin_ga_rv_extend = 0 if dem_prim_2020 == 1;

label variable nd_pres_app_bin_ga_rv_extend "Trump Approver";
label variable pres_app_bin_ga_rv_extend "Trump Approver";



tab to_2021_ro if nd_pres_app_bin_ga_rv_extend == 1;
tab to_2021_ro if nd_pres_app_bin_ga_rv_extend == 0;

tab to_2020_gen if nd_pres_app_bin_ga_rv_extend == 1;
tab to_2020_gen if nd_pres_app_bin_ga_rv_extend == 0;




#delimit cr

forvalues k = 24(1)75{

#delimit;
set more off;
reghdfe to_2021_ro nd_pres_app_bin_ga_rv_extend   if age <= `k' & to_2014_gen == 1 & to_2016_gen == 1 & to_2018_gen == 1 & to_2020_gen == 1, 
absorb(precinct_ID i.age i.female#race_inds1 i.female#race_inds2 i.female#race_inds3 i.female#race_inds4 i.female#race_inds5 race_inds6) vce(cluster precinct_ID);
estimates store age_`k'_cutoff;

#delimit cr

}


#delimit;
coefplot (age_24_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 24))
(age_25_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 25))  (age_26_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 26))
(age_27_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 27))  (age_28_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 28))
(age_29_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 29))  (age_30_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 30))
(age_31_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 31))  (age_32_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 32))
(age_33_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 33))  (age_34_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 34))
(age_35_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 35))  (age_36_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 36))
(age_37_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 37))  (age_38_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 38))
(age_39_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 39))  (age_40_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 40))
(age_41_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 41))  (age_42_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 42))
(age_43_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 43))  (age_44_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 44))
(age_45_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 45))  (age_46_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 46))
(age_47_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 47))  (age_48_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 48))
(age_49_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 49))  (age_50_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 50))
(age_51_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 51))  (age_52_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 52))
(age_53_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 53))  (age_54_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 54))
(age_55_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 55))  (age_56_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 56))
(age_57_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 57))  (age_58_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 58))
(age_59_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 59))  (age_60_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 60))
(age_61_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 61))  (age_62_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 62))
(age_63_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 63))  (age_64_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 64))
(age_65_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 65))  (age_66_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 66))
(age_67_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 67))  (age_68_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 68))
(age_69_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 69))  (age_70_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 70))
(age_71_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 71))  (age_72_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 72))
(age_73_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 73))  (age_74_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 74))
(age_75_cutoff,  rename(nd_pres_app_bin_ga_rv_extend = 75))
,  pstyle(p1) keep(nd_pres_app_bin_ga_rv_extend) legend(off) yline(0) xlabel(,labsize(vsmall))  vertical title("Restrict Analysis to Respondents Below Age Cutoff") graphregion(color(white)) bgcolor(white)  ;


graph export "Cross_Sectional_Varying_AgeCutoff.pdf", replace;

drop _est_age*;


estimates clear;





#delimit cr
forvalues m = 0(1)1{
forvalues l = 0(1)1{
forvalues k = 0(1)1{
forvalues j = 0(1)1{

reghdfe to_2021_ro nd_pres_app_bin_ga_rv_extend   ///
if to_2014_gen == `j' & to_2016_gen == `k' & to_2018_gen == `l' & to_2020_gen == `m', ///
absorb(precinct_ID i.age i.female#race_inds1 i.female#race_inds2 i.female#race_inds3 i.female#race_inds4 i.female#race_inds5 i.female race_inds6)  vce(cluster precinct_ID)

estimates store eb_`j'_`k'_`l'_`m'


}
}
}
}



#delimit;
coefplot (eb_*), keep(nd_pres_app_bin_ga_rv_extend) asequation swapnames coeflabels(eb_0_0_0_0 = `""No" "No" "No" "No""' eb_0_0_0_1 = `""No" "No" "No" "Yes""' eb_0_0_1_0 = `""No" "No" "Yes" "No""' eb_0_1_0_0 =  `""No" "Yes" "No" "No""' eb_1_0_0_0 =  `""Yes" "No" "No" "No""' eb_0_0_1_1 = `""No" "No" "Yes" "Yes""' eb_0_1_0_1 = `""No" "Yes" "No" "Yes""' eb_1_0_0_1 = `""Yes" "No" "No" "Yes""' eb_0_1_1_0 = `""No" "Yes" "Yes" "No""' eb_1_0_1_0 = `""Yes" "No" "Yes" "No""'  eb_1_1_0_0 = `""Yes" "Yes" "No" "No""' eb_0_1_1_1 = `""No" "Yes" "Yes" "Yes""' eb_1_0_1_1 = `""Yes" "No" "Yes" "Yes""' eb_1_1_0_1 = `""Yes" "Yes" "No" "Yes""'  eb_1_1_1_0 = `""Yes" "Yes" "Yes" "No""'  eb_1_1_1_1 = `""Yes" "Yes" "Yes" "Yes""')
 vertical title("")
graphregion(fcolor(white) lcolor(white) lwidth(vvvthin) ifcolor(white) ilcolor(white) 
ilwidth(vvvthin)) ciopts(lwidth(medium) lcolor(black));


graph export "Survey_CS_ExactTOMatching.pdf", replace;

estimates clear;




*Cross-Sectional Conditional on Always Turning Out;
eststo: reg to_2021_ro nd_pres_app_bin_ga_rv_extend if to_2014_gen == 1 & to_2016_gen == 1 & to_2018_gen == 1 & to_2020_gen == 1 , robust cluster(precinct_ID);
estadd local rally_inds "No";
estadd local prec_FEs "No";
estadd local demog_FEs "No";


eststo: reghdfe to_2021_ro nd_pres_app_bin_ga_rv_extend if to_2014_gen == 1 & to_2016_gen == 1 & to_2018_gen == 1 & to_2020_gen == 1, 
absorb(precinct_ID)  vce(cluster precinct_ID);
estadd local rally_inds "No";
estadd local prec_FEs "Yes";
estadd local demog_FEs "No";


eststo: reghdfe to_2021_ro nd_pres_app_bin_ga_rv_extend   
if to_2014_gen == 1 & to_2016_gen == 1 & to_2018_gen == 1 & to_2020_gen == 1, 
absorb(precinct_ID i.age i.female#race_inds1 i.female#race_inds2 i.female#race_inds3 i.female#race_inds4 i.female#race_inds5 i.female race_inds6)  vce(cluster precinct_ID);
estadd local rally_inds "No";
estadd local prec_FEs "Yes";
estadd local demog_FEs "Yes";





#delimit;
esttab using CS_Always_Turnout_PB.tex, 
note("Robust standard errors clustered at precinct level reported in parentheses")  
label se star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mlabels("" "" "" "") r2 obslast keep(nd_pres_app_bin_ga_rv_extend _cons)
title("Prob. Turnout in 2021 Runoff Among Registrants who Turned Out in 2014, 2016, 2018, and 2020 \label{CSAlwaysTurnout}") replace  scalars( 
"prec_FEs Precinct FEs" "demog_FEs Demographic FEs");
eststo clear;


reghdfe to_2021_ro nd_pres_app_bin_ga_rv_extend   
if to_2014_gen == 1 & to_2016_gen == 1 & to_2018_gen == 1 & to_2020_gen == 1 & rep_prim_2020 == 1, 
absorb(precinct_ID i.age i.female#race_inds1 i.female#race_inds2 i.female#race_inds3 i.female#race_inds4 i.female#race_inds5 i.female race_inds6)  vce(cluster precinct_ID);




#delimit;
*Lagged DV Models;
label variable to_2020_gen "Turnout in 2020 General";


eststo: reg to_2021_ro nd_pres_app_bin_ga_rv_extend to_2020_gen, robust cluster(precinct_ID);
estadd local prec_FEs "No";
estadd local demog_FEs "No";


eststo:reghdfe to_2021_ro nd_pres_app_bin_ga_rv_extend to_2020_gen, absorb(precinct_ID)  vce(cluster precinct_ID);
estadd local prec_FEs "Yes";
estadd local demog_FEs "No";


eststo:reghdfe to_2021_ro nd_pres_app_bin_ga_rv_extend to_2020_gen, absorb(precinct_ID i.age i.female#race_inds1 i.female#race_inds2 i.female#race_inds3 i.female#race_inds4 i.female#race_inds5 i.female race_inds6)  vce(cluster precinct_ID);
estadd local prec_FEs "Yes";
estadd local demog_FEs "Yes";



esttab using Alt_ID_TO_Models_PB.tex, 
note("Robust standard errors clustered at precinct level reported in parentheses")  
label se star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mlabels("" "" "" "") r2 obslast keep(nd_pres_app_bin_ga_rv_extend to_2020_gen _cons)
title("Prob. Turnout in 2021 Runoff\label{AltIDTOModels}") replace  scalars( 
"prec_FEs Precinct FEs" "demog_FEs Demog. FEs");
eststo clear;







#delimit;
*Reshaping for Fixed Effects Regressions;
keep age  nd_pres_app_bin_ga_rv_extend in_balanced_panel rep_prim_2020 dem_prim_2020 only_2016g_2020g dalton_msa valdosta_msa to_2021_ro reg_id county_code  pres_app_bin_ga_rv_extend precinct_ID registration_year to_2020_gen to_2020_prim to_2018_ro to_2018_gen to_2018_prim to_2016_gen to_2014_gen y2020_001_party y2016_010_party race_inds6;

reshape long to_, i(reg_id) j(elec_yt) string;

*Dropping Missing Outcomes Due to Registration Date After Election Cycle;
drop if to_ == .;
tab elec_yt, gen(elec_yt_);





#delimit cr
forvalues k = 1(1)8{
	gen tr_elec_yt_`k' = elec_yt_`k'*pres_app_bin_ga_rv_extend
	gen r2020_elec_yt_`k' = elec_yt_`k'*rep_prim_2020
	
	gen ndem_tr_elec_yt_`k' = tr_elec_yt_`k'
	replace ndem_tr_elec_yt_`k' = 0 if dem_prim_2020 == 1
	}
	
	
#delimit;
	
label variable tr_elec_yt_1 "2014 Gen. $\times$ Trump Approver (SL Only)";
label variable tr_elec_yt_2 "2016 Gen. $\times$ Trump Approver (SL Only)";
label variable tr_elec_yt_3 "2018 Gen. $\times$ Trump Approver (SL Only)";
label variable tr_elec_yt_4 "2018 Prim. $\times$ Trump Approver (SL Only)";
label variable tr_elec_yt_5 "2018 Runoff $\times$ Trump Approver (SL Only)";
label variable tr_elec_yt_6 "2020 Gen. $\times$ Trump Approver (SL Only)";
label variable tr_elec_yt_7 "2020 Prim. $\times$ Trump Approver (SL Only)";
label variable tr_elec_yt_8 "2021 Runoff $\times$ Trump Approver (SL Only)";

label variable ndem_tr_elec_yt_1 "2014 Gen. $\times$ Trump Approver";
label variable ndem_tr_elec_yt_2 "2016 Gen. $\times$ Trump Approver";
label variable ndem_tr_elec_yt_3 "2018 Gen. $\times$ Trump Approver";
label variable ndem_tr_elec_yt_4 "2018 Prim. $\times$ Trump Approver";
label variable ndem_tr_elec_yt_5 "2018 Runoff $\times$ Trump Approver";
label variable ndem_tr_elec_yt_6 "2020 Gen. $\times$ Trump Approver";
label variable ndem_tr_elec_yt_7 "2020 Prim. $\times$ Trump Approver";
label variable ndem_tr_elec_yt_8 "2021 Runoff $\times$ Trump Approver";

label variable r2020_elec_yt_1 "2014 Gen. $\times$ 2020 Rep. Prim.";
label variable r2020_elec_yt_2 "2016 Gen. $\times$ 2020 Rep. Prim.";
label variable r2020_elec_yt_3 "2018 Gen. $\times$ 2020 Rep. Prim.";
label variable r2020_elec_yt_4 "2018 Prim. $\times$ 2020 Rep. Prim.";
label variable r2020_elec_yt_5 "2018 Runoff $\times$ 2020 Rep. Prim.";
label variable r2020_elec_yt_6 "2020 Gen. $\times$ 2020 Rep. Prim.";
label variable r2020_elec_yt_7 "2020 Prim. $\times$ 2020 Rep. Prim.";
label variable r2020_elec_yt_8 "2021 Runoff $\times$ 2020 Rep. Prim.";



label variable elec_yt_1 "2014 Gen.";
label variable elec_yt_2 "2016 Gen.";
label variable elec_yt_3 "2018 Gen.";
label variable elec_yt_4 "2018 Prim.";
label variable elec_yt_5 "2018 Runoff";
label variable elec_yt_6 "2020 Gen.";
label variable elec_yt_7 "2020 Prim.";
label variable elec_yt_8 "2021 Runoff";

gen ro_valdosta_msa = valdosta_msa* elec_yt_8;
gen ro_dalton_msa = dalton_msa* elec_yt_8;

label variable elec_yt_8 "2021 Runoff";
	



*Histogram of within county coefficients;


gen elec_202021 = 1 if elec_yt_6 == 1 | elec_yt_8 == 1;
gen sample_inclusion = 1 if elec_202021 == 1;


gen coeff_county = .;
gen se_coeff_county = .;
gen N_county = .;

#delimit cr

forvalues k = 1/159{


	reghdfe to_ ndem_tr_elec_yt_8 elec_yt_8 if sample_inclusion == 1 & county_code == `k',  absorb(reg_id) vce(cluster reg_id ) level(95)

	local coeff = e(b)[1,1]
	replace coeff_county = `coeff' in `k'
	
	local se_coeff = sqrt(e(V)[1,1])
	replace se_coeff_county = `se_coeff' in `k'
	
	local num_obs_county = e(N_full)
	replace N_county = `num_obs_county' in `k'

	
}



#delimit;


gen t_stat_county= coeff_county/se_coeff_county;




graph twoway (kdensity t_stat_county, xline(-1.96 1.96, lpattern(dash))),  ytitle("Density") xtitle("t-Stats from County-Specific Regressions") xscale(range(-15 15)) xlabel(-15(5)15) graphregion(color(white)) bgcolor(white);  
graph export "Kdensity_Tstat_county.pdf", replace;
 
sum t_stat_county if t_stat_county < -1.96;
sum t_stat_county if t_stat_county < 0;
sum t_stat_county if t_stat_county > 1.96;

drop coeff_county se_coeff_county t_stat_county N_county;

  
#delimit;

capture drop sample_inclusion;
capture drop elec_202021;





gen elec_202021 = 1 if elec_yt_6 == 1 | elec_yt_8 == 1;
gen gen_elec_spec = 1 if elec_yt_1 == 1 | elec_yt_2 == 1 | elec_yt_3 == 1 | elec_yt_6 == 1 | elec_yt_8 == 1;








#delimit;

gen sample_inclusion = 1 if elec_202021 == 1;



eststo: reghdfe to_ ndem_tr_elec_yt_8 elec_yt_8  if sample_inclusion == 1,  
absorb(reg_id) vce(cluster reg_id ) level(95);
estadd local num_indiv =  e(N_clust);

estadd local indiv_FE "Yes";
estadd local samp_ex "No";
estadd local county_elec_FE "No";



drop sample_inclusion;
drop elec_202021;



#delimit;
capture drop gen_elec_spec;


gen gen_elec_spec = 1 if elec_yt_1 == 1 | elec_yt_2 == 1 | elec_yt_3 == 1 | elec_yt_6 == 1 | elec_yt_8 == 1;

gen sample_inclusion = 1 if gen_elec_spec == 1;
local genelec_cycle_fes elec_yt_1-elec_yt_2 elec_yt_8 elec_yt_3;
	
	


eststo: reghdfe to_ ndem_tr_elec_yt_8 ndem_tr_elec_yt_3 ndem_tr_elec_yt_2 ndem_tr_elec_yt_1  `genelec_cycle_fes'  if sample_inclusion == 1,  
absorb(reg_id) vce(cluster reg_id ) level(95);
estadd local num_indiv =  e(N_clust);
estadd local indiv_FE "Yes";
estadd local samp_ex "No";
estadd local county_elec_FE "No";




eststo: reghdfe to_ ndem_tr_elec_yt_8 ndem_tr_elec_yt_3 ndem_tr_elec_yt_2 ndem_tr_elec_yt_1 `genelec_cycle_fes'  if sample_inclusion == 1 & only_2016g_2020g != 1,  
absorb(reg_id) vce(cluster reg_id ) level(95);
estadd local num_indiv =  e(N_clust);
estadd local indiv_FE "Yes";
estadd local samp_ex "Yes";
estadd local county_elec_FE "No";



eststo: reghdfe to_ ndem_tr_elec_yt_8 ndem_tr_elec_yt_3 ndem_tr_elec_yt_2 ndem_tr_elec_yt_1   if sample_inclusion == 1,  
	absorb(reg_id i.county_code#i.elec_yt_1 i.county_code#i.elec_yt_2 i.county_code#i.elec_yt_3 i.county_code#i.elec_yt_8 )
	 vce(cluster reg_id )
 level(95);
estadd local num_indiv =  e(N_clust);
estadd local indiv_FE "Yes";
estadd local samp_ex "Yes";
estadd local county_elec_FE "Yes";

 




esttab using FE_AllGen_Models_PB.tex, 
note("Robust standard errors clustered at individual level reported in parentheses")  
label se star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mlabels("" "" "" "") r2 obslast
keep(ndem_tr_elec_yt_8 ndem_tr_elec_yt_3 ndem_tr_elec_yt_2 ndem_tr_elec_yt_1 elec_yt_8 elec_yt_3 elec_yt_2 elec_yt_1)
order(ndem_tr_elec_yt_8 ndem_tr_elec_yt_3 ndem_tr_elec_yt_2 ndem_tr_elec_yt_1 elec_yt_8 elec_yt_3 elec_yt_2 elec_yt_1)
title("Prob. Turnout \label{FEAllGenModelsPB}") replace  scalars( "indiv_FE Individual FEs" 
"samp_ex Ex. Registrants"  "county_elec_FE County by Election FE" "num_indiv Num. Indivs.");
eststo clear;




drop sample_inclusion;


capture drop pretrend_t;


#delimit;
set more off;	

gen pretrend_t = 1 if elec_yt_1 == 1;
replace pretrend_t = 2 if elec_yt_2 == 1;
replace pretrend_t = 3 if elec_yt_3 == 1;
replace pretrend_t = 4 if elec_yt_6 == 1;
replace pretrend_t = 0 if elec_yt_8 == 1;


local genelec_cycle_fes elec_yt_1-elec_yt_2 elec_yt_8 elec_yt_3;

gen sample_inclusion = 1 if gen_elec_spec == 1 & in_balanced_panel == 1;


eststo: reghdfe to_ ndem_tr_elec_yt_8 ndem_tr_elec_yt_3 ndem_tr_elec_yt_2 ndem_tr_elec_yt_1 `genelec_cycle_fes'  if sample_inclusion == 1,  
absorb(reg_id) vce(cluster reg_id ) level(95);
estadd local num_indiv =  e(N_clust);
estadd local indiv_FE "Yes";

drop sample_inclusion; 

gen sample_inclusion = 1 if gen_elec_spec == 1 & race_inds6 == 1;
	
eststo: reghdfe to_ ndem_tr_elec_yt_8 ndem_tr_elec_yt_3 ndem_tr_elec_yt_2 ndem_tr_elec_yt_1 `genelec_cycle_fes'  if sample_inclusion == 1,  
absorb(reg_id) vce(cluster reg_id ) level(95);
estadd local num_indiv =  e(N_clust);

estadd local indiv_FE "Yes";

drop sample_inclusion; 



local genelec_cycle_fes elec_yt_1-elec_yt_2 elec_yt_8 elec_yt_3;
local tr_genelec_inters tr_elec_yt_1 tr_elec_yt_2 tr_elec_yt_3 tr_elec_yt_8;


gen sample_inclusion = 1 if gen_elec_spec == 1;

eststo: reghdfe to_ `tr_genelec_inters' `genelec_cycle_fes'  if sample_inclusion == 1,  
absorb(reg_id) vce(cluster reg_id ) level(95);
estadd local num_indiv =  e(N_clust);

estadd local indiv_FE "Yes";

drop sample_inclusion; 




esttab using FE_Robustness_AllGen_PB.tex, 
note("Robust standard errors clustered at individual level reported in parentheses")  
label se star(+ 0.10 * 0.05 ** 0.01 *** 0.001) mlabels("Bal. Panel" "White Regs." "SL Classifier" ) 
r2 obslast
keep(ndem_tr_elec_yt_8 ndem_tr_elec_yt_3 ndem_tr_elec_yt_2 ndem_tr_elec_yt_1 elec_yt_8 elec_yt_3 elec_yt_2 elec_yt_1)
order(ndem_tr_elec_yt_8 ndem_tr_elec_yt_3 ndem_tr_elec_yt_2 ndem_tr_elec_yt_1  elec_yt_8 elec_yt_3 elec_yt_2 elec_yt_1)
rename(tr_elec_yt_8 ndem_tr_elec_yt_8 tr_elec_yt_3 ndem_tr_elec_yt_3 tr_elec_yt_2 ndem_tr_elec_yt_2 tr_elec_yt_1 ndem_tr_elec_yt_1  )
title("Prob. Turnout \label{FERobustnessAllGen}") replace  scalars( "indiv_FE Individual FEs" 
 "num_indiv Num. Indivs.");
eststo clear;

